<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
<head>
    <%@ include file="/platform/style.jsp"%>
    <%@ include file="/plugins/plupload2/plupload.jsp"%>
    <script type="text/javascript" src="<%=request.getContextPath() %>/plugins/oss/upload.js"></script>
    <style>
        img.channelimg{height:110px;height:50px}
    </style>
    <script>

        function caozFormatter(value,row){
            var h='';
            if(value.length>6)h+='<span style="display:inline-block;width:103px;" class="marginR8"></span>';
            else h+='<a href="javascript:void(0);" class="ui_btn marginR8" onclick="addB(\''+value+'\','+row.id+')">添加二级栏目</a>';
            h+='<a href="javascript:void(0);" class="ui_btn marginR8" onclick="edit('+row.id+',\''+value+'\')">编辑</a><a href="javascript:void(0);" class="ui_btn" onclick="del('+row.id+')">删除</a>';
            return h;
        }
        function imgFormatter(value,row){
            if(value)return "<img src='"+fileserver+value+"' class='channelimg'>";
            else return '';
        }
        function addA(){
            $w.openDialog({url:ctx+'/information/InformationPage@showChannelEditA.page?bean.code='+$getByName("code").val(),title:"添加专题栏目",w:700,h:450,maximized:true,afterClose:function(re){
                if(re){
                    $('#tree').treegrid("reload");
                }
            }});
        }
        function addB(code,id){
            $w.openDialog({url:ctx+'/information/InformationPage@showChannelEditB.page?bean.code='+code,title:"添加子栏目",w:700,h:450,maximized:true,afterClose:function(re){
                if(re){
                    $('#tree').treegrid("reload");
                }
            }});
        }
        function edit(id,code){
            if(code.length>6)
                editB(id);
            else{
                $w.openDialog({url:ctx+'/information/InformationPage@showChannelEditA.page?bean.id='+id,title:"修改专题栏目",w:700,h:450,maximized:true,afterClose:function(re){
                    if(re){
                        $('#tree').treegrid("update",{
                            id:id,
                            row:{
                                id: re.id,
                                code: re.code,
                                name:re.name,
                                photo:re.photo,
                                url:re.url,
                                orderno:re.orderno
                            }
                        })
                    }
                }});
            }
        }
        function editB(id){
            $w.openDialog({url:ctx+'/information/InformationPage@showChannelEditB.page?bean.id='+id,title:"修改子栏目",w:700,h:450,maximized:true,afterClose:function(re){
                if(re){
                    $('#tree').treegrid("update",{
                        id:id,
                        row:{
                            id: re.id,
                            code: re.code,
                            name:re.name,
                            photo:re.photo,
                            url:re.url,
                            orderno:re.orderno
                        }
                    })
                }
            }});
        }

        function del(id){
            var chs=$('#tree').treegrid("getChildren",id);
            if(chs.length>0){
                window.parent.$w.infoMsg("有子栏目不能删除！");
                return false
            }
            window.parent.$w.confirmMsg("确定删除？", function(r){
                if(r){
                    $w.doUrl(ctx+"/information/InformationPage@delChannel.page?bean.id="+id,{},function(json){
                        $('#tree').treegrid("reload");
                    })
                }
            })
        }
    </script>

<body class="easyui-layout">
<div data-options="region:'center'" class="bodybg">
    <input name="code" value="<%=request.getParameter("code")==null?"":request.getParameter("code") %>" type="hidden">
    <div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
        <a href="javascript:;" class="easyui-linkbutton" iconCls="icon_add" plain="true" onclick="addA()">添加专题栏目</a>
    </div>
    <div class="ui_line" style="margin-top:10px"></div>

    <table id="tree" class="easyui-treegrid"
           data-options="fit:true,border:false,rownumbers: true,
			url: '<%=path %>/information/InformationPage@loadChannel.page?bean.code=<%=request.getParameter("code") %>',
			idField: 'id',
			fitColumns:true,
			treeField: 'name'" style="width:100%">
        <thead>
        <tr>
            <th data-options="field:'id',width:40" align="center">ID</th>
            <th data-options="field:'name',width:fixWidth(0.2)">栏目名称</th>
            <th data-options="field:'photo',width:120,formatter:imgFormatter" align="center">栏目图片</th>
            <th data-options="field:'url',width:fixWidth(0.2)"  align="center">链接网址</th>
            <th data-options="field:'orderno',width:fixWidth(0.1)"  align="center">排序</th>
            <th data-options="field:'code',width:250,formatter:caozFormatter" align="center">操作</th>
        </tr>
        </thead>
    </table>
</div>

</body>
</html>
